package com.j.lemon.learn.clickhouse;

import com.alibaba.druid.pool.DruidDataSource;
import com.opencsv.CSVReader;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.CollectionUtils;
import ru.yandex.clickhouse.ClickHouseArray;

import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lijunjun
 */
public class CkTest23 {
    public static void main(String[] args) throws SQLException {
        final ExecutorService executorService = new ThreadPoolExecutor(80, 80, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(10000), r -> new Thread(r, "executeSql-thread"));
        String driverClassName = "ru.yandex.clickhouse.ClickHouseDriver";
        String url = "jdbc:clickhouse://10.28.149.247:8123/default";
        String userName = "audit4a";
        String password = "rryzggTR";
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        dataSource.setTestWhileIdle(true);
        dataSource.setMaxActive(100);
        dataSource.setMaxWait(60000);
        dataSource.setTestOnBorrow(false);
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        List<Map<String, Object>> data =
                jdbcTemplate.queryForList("select * from ais_adv_auth_cfg");
        for (Map<String, Object> datum : data) {
            ClickHouseArray pvalueLevel = (ClickHouseArray) datum.get("bd_org_id");
            long s [] = (long[]) pvalueLevel.getArray();
            System.out.println("1");
        }
        System.out.println("done");


    }
}
